package cn.haohaowo.entity;

import java.io.Serializable;

import cn.haohaowo.service.BookBizService;
import cn.haohaowo.service.impl.BookBizServiceImpl;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CartItem implements Serializable {

	private static final long serialVersionUID = -1014427200669332238L;
	
	private Integer boookid;
	private Integer quantity;

	private Book book;
	
	public CartItem(Book book){
		this(book,1);
	}

	public CartItem(Book book,Integer quantity){
		this.boookid = book.getId();
        this.book = book;
		this.quantity = (quantity < 1)?  1:quantity;
	}
	
	public Book getBook(){
		return book;
	}
	
	public Integer getTotalPrice(){
		return book.getPrice() * quantity;
	}
	
	public Integer getTotalOrgiPrice(){
		return book.getOrgiPrice() * quantity;
	}
	
	public void incrementQuantity() {
		quantity++;
	}
	
	public OrderDetail createOrderDetail(){
		OrderDetail od = new OrderDetail();
		od.setBook(book);
		od.setQuantity(this.quantity);
		od.setUnitPrice(book.getPrice());
		
		return od;
	}
	
	public Integer getBoookid() {
		return boookid;
	}

	public void setBoookid(Integer boookid) {
		this.boookid = boookid;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public Integer getQuantity() {
		return quantity;
	}
	

}
